<link rel='stylesheet' type='text/css' href='<?php echo $this->baseUrl() ?>/public/css/jquery-ui/jquery-ui-1.10.3.css'/>
<link rel='stylesheet' type='text/css' href='<?php echo $this->baseUrl() ?>/public/css/input.css'/>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/fancybox/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl() ?>/public/js/fancybox/jquery.fancybox.css" />
<div id="input-content">
    <div class='wrap-export'>
        <a href="<?php echo $this->baseUrl() ?>/service/export-pdf/giid/<?php echo $this->gi->id ?>" 
           target='_blank' <?php echo empty($this->gi->ats) ? "onclick='return false'" : "" ?> >
            <span class='button' <?php echo empty($this->gi->ats) ? "style='color: #CCC'" : "" ?>>Export Trip Account</span>
        </a>        
        <a href="<?php echo $this->baseUrl() ?>/service/profoma/giid/<?php echo $this->gi->id ?>" target='_blank'>
            <span class='button'>Export Profoma</span>
        </a>
    </div>
    <div class="input-step" id="wrap-general-info">
        <div class="step-content">
            <h1 class="first"> General information</h1>
            <div class="item">
                <label for='refno'>Ref No.</label>
                <div class="reselect">
                    <?php echo $this->gi->ref_no ?>
                </div>
            </div>
            <div class="item">
                <label for="customer_name">Principal name</label>
                <div class="reselect">
                    <?php echo $this->customer_name ?>
                </div>
            </div>
            <div class="item">
                <label for="customer_name">Attn:</label>
                <div class="reselect">
                    <?php if ($this->gi->attn): ?>
                        <?php echo $this->gi->attn ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="vessel">Vessel name</label>
                <div class="reselect">
                    <?php echo $this->gi->vessel ?>
                </div>
            </div>
            <div class="item">
                <label for='purpose_of_call'>Purpose of Call</label>
                <div class="reselect">
                    <?php echo $this->gi->purpose_of_call ?>
                </div>
            </div>
            <div class="item">
                <label for="gtr">GRT</label>
                <div class="reselect">
                    <?php echo $this->gi->gtr ?>
                </div>
            </div>
            <div class="item">
                <label for='port_of_call'>Port of Call</label>
                <div class="reselect">
                    <?php echo $this->port_of_call_name ?>
                </div>
            </div>
            <div class="item">
                <label for='buoy'>Buoy/Perth</label>
                <div class="reselect">
                    <?php if ($this->gi->buoy > 0): ?>
                        <?php echo $this->buoy_name ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for='last_port_of_call'>Last Port of Call:</label>
                <div class="reselect">
                    <?php if ($this->gi->last_port_of_call != '-1'): ?>
                        <?php echo $this->gi->last_port_of_call ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for='next_port_of_call'>Next Port of Call:</label>
                <div class="reselect">
                    <?php if ($this->gi->next_port_of_call != '-1'): ?>
                        <?php echo $this->gi->next_port_of_call ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for='commodities'>Commodities</label>
                <div class="reselect">
                    <?php echo $this->gi->commodities ?>
                </div>
            </div>
            <div class="item">
                <label for='quantity'>Quantity</label>
                <div class="reselect">
                    <?php if ($this->gi->quantity): ?>
                        <?php if ((int) $this->gi->quantity != $this->gi->quantity): ?>
                            <?php echo number_format($this->gi->quantity, 2, '.', ',') ?>
                        <?php else: ?>
                            <?php echo number_format($this->gi->quantity, 0, '.', ',') ?>
                        <?php endif; ?>
                        <?php echo $this->gi->quantity_unit ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="voyage_no">Voyage No.</label>
                <div class="reselect">
                    <?php if ($this->gi->voyage_no): ?>
                        <?php echo $this->gi->voyage_no ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="flag">Flag</label>
                <div class="reselect">
                    <?php echo $this->gi->flag ?>
                </div>
            </div>
            <div class="item">
                <label for="eta">ETA:</label>
                <div class="reselect">
                    <?php if ($this->gi->eta): ?>
                        <?php echo date(DATE_FORMAT, $this->gi->eta) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="ata">ATA:</label>
                <div class="reselect">
                    <?php if ($this->gi->ata): ?>
                        <?php echo date(DATE_FORMAT, $this->gi->ata) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="etb">ETB:</label>
                <div class="reselect">
                    <?php if ($this->gi->etb): ?>
                        <?php echo date(DATE_FORMAT, $this->gi->etb) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="atb">ATB:</label>
                <div class="reselect">
                    <?php if ($this->gi->atb): ?>
                        <?php echo date(DATE_FORMAT, $this->gi->atb) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="ets">ETS:</label>
                <div class="reselect">
                    <?php if ($this->gi->ets): ?>
                        <?php echo date(DATE_FORMAT, $this->gi->ets) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="ats">ATS:</label>
                <div class="reselect">
                    <?php if ($this->gi->ats): ?>
                        <?php echo date(DATE_FORMAT, intval($this->gi->ats)) ?>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="vessel_on_arrival">Vessel on Arrival</label>
                <div class="reselect">
                    <?php if ($this->gi->vessel_on_arrival): ?>
                        <div style="width: 60%">
                            <a href="<?php echo UPLOAD_URL . $this->gi->vessel_on_arrival ?>" class="fancybox" data-fancybox-group="gallery1">
                                <img alt="No image" width="100px" height="50px" style='padding:10px 0px;' src="<?php echo UPLOAD_URL . $this->gi->vessel_on_arrival ?>"/>
                            </a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            <div class="item">
                <label for="vessel_on_arrival">Vessel on Departure</label>
                <div class="reselect">
                    <?php if ($this->gi->vessel_on_departure): ?>
                        <div style="width: 60%">
                            <a href="<?php echo UPLOAD_URL . $this->gi->vessel_on_departure ?>"  class="fancybox" data-fancybox-group="gallery1">
                                <img alt="No image" width="100px" height="50px" style='padding:10px 0px;' src="<?php echo UPLOAD_URL . $this->gi->vessel_on_departure ?>"/>

                            </a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            <div style="clear: both;">&nbsp;</div>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Loading' || $this->gi->purpose_of_call == 'Discharging'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-cargo-operations" <?php echo $display ?>>
                <h1 class="first"> Cargo operations</h1>
                <div class="item">
                    <label for="net_weight">Commenced cargo ops:</label>
                    <div class="reselect">
                        <?php if ($this->gi->commenced_cargo): ?>
                            <?php echo $this->gi->commenced_cargo ? date(DATE_FORMAT, $this->gi->commenced_cargo) : "" ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="gross_weight">Completed cargo ops:</label>
                    <div class="reselect">
                        <?php if ($this->gi->completed_cargo): ?>
                            <?php echo $this->gi->completed_cargo ? date(DATE_FORMAT, $this->gi->completed_cargo) : "" ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <span id='wrap_loaded_cargo' style='<?php echo $this->gi->purpose_of_call == 'Discharging' ? 'display:none' : '' ?>'>
                    <div class="item">
                        <label for="total_cargo_loaded_last_24h">Total cargo loaded last 24 hour:</label>
                        <div class="reselect">
                            <?php if ($this->gi->total_cargo_loaded_last_24h): ?>
                                <?php echo Core_Util::formatNumber($this->gi->total_cargo_loaded_last_24h) . ' ' . $this->gi->tcll24h_unit ?> 
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label for="total_cargo_loaded_uptodate">Total cargo loaded up to date:</label>
                        <div class="reselect">
                            <?php if ($this->gi->total_cargo_loaded_uptodate): ?>
                                <?php echo Core_Util::formatNumber($this->gi->total_cargo_loaded_uptodate) . ' ' . $this->gi->tclutd_unit ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label for="balance_to_load">Balance to load:</label>
                        <div class="reselect">
                            <?php if ($this->gi->quantity && $this->gi->total_cargo_loaded_uptodate): ?>
                                <?php echo Core_Util::formatNumber($this->gi->quantity - $this->gi->total_cargo_loaded_uptodate) ?> <?php echo $this->gi->tclutd_unit ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                </span>
                <span id='wrap_discharged_cargo' style='<?php echo $this->gi->purpose_of_call == 'Loading' ? 'display:none' : '' ?>'>
                    <div class="item">
                        <label for="total_cargo_discharged_last_24h">Total cargo discharged last 24 hour:</label>
                        <div class="reselect">
                            <?php if ($this->gi->total_cargo_discharged_last_24h): ?>
                                <?php echo Core_Util::formatNumber($this->gi->total_cargo_discharged_last_24h) . ' ' . $this->gi->tcdl24h_unit ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label for="total_cargo_discharged_uptodate">Total cargo discharged up to date:</label>
                        <div class="reselect">
                            <?php if ($this->gi->total_cargo_discharged_uptodate): ?>
                                <?php echo Core_Util::formatNumber($this->gi->total_cargo_discharged_uptodate) . ' ' . $this->gi->tcdutd_unit ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="item">
                        <label for="balance_to_load">Balance to discharge:</label>
                        <div class="reselect">
                            <?php if ($this->gi->quantity && $this->gi->total_cargo_discharged_uptodate): ?>
                                <?php echo Core_Util::formatNumber($this->gi->quantity - $this->gi->total_cargo_discharged_uptodate) ?> <?php echo $this->gi->tcdutd_unit ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                    </div>
                </span>
                <div class="item">
                    <label for="net_weight">Net weight:</label>
                    <div class="reselect">
                        <?php if ($this->gi->cargo_net_weight): ?>
                            <?php echo Core_Util::formatNumber($this->gi->cargo_net_weight) . ' ' . $this->gi->net_weight_unit ?> 
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>          
                <div class="item">
                    <label for="gross_weight">Gross weight:</label>
                    <div class="reselect">
                        <?php if ($this->gi->cargo_gross_weight): ?>
                            <?php echo Core_Util::formatNumber($this->gi->cargo_gross_weight) . ' ' . $this->gi->gross_weight_unit ?>
                        <?php else: ?> 
                            N/A
                        <?php endif; ?>
                    </div>
                </div>  
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Crew change'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-crew-service" <?php echo $display ?>>
                <h1 class="first"> Crew Service</h1>
                <div class="item">
                    <label>On-signers status: </label>
                    <div class="reselect" style="float:left">
                        <?php if ($this->gi->on_signer_status): ?>
                            <?php echo $this->gi->on_signer_status ?> - 
                            <?php echo $this->gi->on_signer_status_date ? date(DATE_FORMAT, $this->gi->on_signer_status_date) : '' ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>  
                <div class="item">
                    <label>Off-signers status: </label>
                    <div class="reselect" style="float:left">
                        <?php if ($this->gi->off_signer_status): ?>
                            <?php echo $this->gi->off_signer_status ?> - 
                            <?php echo $this->gi->off_signer_status_date ? date(DATE_FORMAT, $this->gi->off_signer_status_date) : '' ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>   
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call == 'Dunnage'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-dunnage" <?php echo $display ?>>
                <h1 class="first"> Dunnage</h1>
                <div class="item">
                    <label for="commenced_dunnage">Commenced dunnage</label>
                    <div class="reselect">
                        <?php if ($this->gi->commenced_dunnage): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->commenced_dunnage) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div class="item">
                    <label for="completed_dunnage">Completed dunnage</label>
                    <div class="reselect" style="float:left">
                        <?php if ($this->gi->completed_dunnage): ?>
                            <?php echo date(DATE_FORMAT, $this->gi->completed_dunnage) ?>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </div>
                </div>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php $display = "style='display:none'" ?>
            <?php if ($this->gi->purpose_of_call != 'Crew change'): ?>
                <?php $display = '' ?>
            <?php endif; ?>
            <span id="wrap-daily-photos" <?php echo $display ?>>
                <h3 class="table"> Daily photos</h3>
                <?php if ($this->input_photos): ?>
                    <?php foreach ($this->input_photos as $photo): ?>
                        <div style='fwidth: 30%; margin: 10px 0px'>
                            <a class="fancybox" data-fancybox-group="gallery2" href="<?php echo UPLOAD_URL . $photo['file'] ?>">
                                <img alt="No image" style='padding:10px 0px;max-width: 200px; max-height: 100px' src="<?php echo UPLOAD_URL . $photo['file'] ?>"/>
                            </a>
                            <div>
                                <?php echo $photo['description'] ?>
                            </div>
                        </div>
                    <?php endforeach; ?>
                <?php endif; ?>
                <div style="clear: both;">&nbsp;</div>
            </span>
            <?php if ($this->gi->purpose_of_call == 'Crew change'): ?>
                <h3 class="first"> Crew documents</h3>
            <?php else: ?>
                <h3 class="first"> Cargo documents</h3>
            <?php endif; ?>
            <?php if ($this->input_docs): ?>
                <?php foreach ($this->input_docs as $doc): ?>
                    <div class="<?php echo $doc['file_type'] ?> file-new">
                        <a href="<?php echo UPLOAD_URL . $doc['file'] ?>" target="_blank">
                            <?php echo $doc['file_name'] ?>
                        </a>
                    </div>
                <?php endforeach; ?>
            <?php endif; ?>
            <div style="clear: both;">&nbsp;</div>
            <h1 class="first"> Remittances detail</h1>
            <table id="tbl_remittances" width="100%" border="0" cellpadding="0" cellspacing="0" class="row">
                <tr>
                    <th scope="col" class="number" width="5%">Remittance No.</th>
                    <th scope="col" class="type" width="15%">From</th>
                    <th scope="col" class="type" width="15%">Date</th>
                    <th scope="col" class="type" width="5%">Amount</th>
                    <th scope="col" class="type" width="15%">Remarks</th>
                </tr>
                <?php $index = 1 ?>
                <?php foreach ($this->remittances_detail as $rem): ?>
                    <tr>
                        <td class="rem_no">
                            <?php echo $index++; ?>
                        </td>
                        <td>
                            <?php echo $rem->fullname ?>
                        </td>
                        <td>
                            <?php echo date('d/m/Y', $rem->date) ?>
                        </td>
                        <td>
                            <?php echo Core_Util::displayCurrrency($rem->amount) ?>
                        </td>
                        <td>
                            <?php echo $rem->remarks ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
            <h1 class="first"> Services</h1>
            <table id="tbl_services" width="100%" border="0" cellpadding="0" cellspacing="0" class="row">
                <tr>
                    <th scope="col" width="15%">Description of Port Expenses</th>
                    <th scope="col" width="2%">Invoice number</th>
                    <th scope="col" width="15%">Amount in USD</th>
                    <th scope="col" width="25%">Remarks</th>
                </tr>
                <?php foreach ($this->services_detail as $service_detail): ?>
                    <tr>
                        <td>
                            <?php echo $service_detail->name ?>
                        </td>
                        <td>
                            <?php echo $service_detail->voucher ?>
                        </td>
                        <td>
                            <?php echo Core_Util::displayCurrrency($service_detail->amount) ?>
                        </td>
                        <td>
                            <?php echo $service_detail->remarks ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
    </div>
</div>
<script>
    $(window).load(function() {
        var left_height = $(".gi_left").height();
        var right_height = $(".gi_right").height();
        if (left_height < right_height) {
            $(".gi_left").height(right_height);
        }
        $(".fancybox").fancybox();
    });
</script>
<style type="text/css">
    .input-step label{
        margin-top: 0px !important;
        white-space: normal;
        width: 40%;
    }
    .input-step .reselect {
        width: 55%;
        float: left !important;
    }
    .reselect{
        white-space: normal;
    }
    .step-content h1 {
        margin-top: 0px;
        margin-bottom: 10px;
    }
    .input-step .item {
        padding: 10px 0px;
    }
    .row th {
        font-size: 10px;
    }
    .row td {
        font-size: 9px;
    }
    .wrap-export {
        padding: 0px;
        font-size: 7px;
    }
    .wrap-export a {
        text-decoration: none;
        color: blue;
        color: #084b8b;
    }
    .export-button {
        top: -2px;
        margin: 0px 5px;
    }
</style>